/*
 * Copyright (C) 2016 The Android Open Source Project
 *  Created by  Ant  2016/9/7  10:29
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ant.cn.activities;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.ant.cn.R;
import com.ant.cn.base.BaseActivity;
import com.ant.cn.utils.AntLog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by baichuan on 2016/9/7.
 */
public class Demo04 extends BaseActivity {
    private Spinner sp;
    private List<String> slt;
    private ArrayAdapter<String> adapter;

    @Override
    public int getLaout() {
        slt = new ArrayList<>();
        String[] stringArray = getResources().getStringArray(R.array.ant_listviwe_data);
        for (int i = 0; i < stringArray.length; i++)
            slt.add(i + ", " + stringArray[i]);
        return R.layout.ac_demo04;
    }

    @Override
    public void initView() {
        sp = (Spinner) findViewById(R.id.ac_demo04_spinner);

    }

    @Override
    public void initData() {
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, slt);
        sp.setAdapter(adapter);
    }

    @Override
    public void initListener() {
        sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

                    String data = sp.getSelectedItem().toString();
                    adapter.remove(sp.getSelectedItem().toString());
                    AntLog.i(TAG, "i=" + i + ", long=" + l + "  all=" + adapter.getCount() + ",  data=" + data);
                   // adapter.notify();

            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

    }
}
